package org.game;

import java.util.Vector;

import org.mathematic.Vec2;
import org.namespace.TexturePhysixActivity;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.SurfaceHolder;

public class Washer extends DinamicObject
{
	private float				minimalSpeed;
	private static final float	staticMinimalSpeedslowness 	= 0.002f;
	private static final float	slowness 					= 0.0005f;
	private static final float  maximalSpeed 				= 0.005f;
	public 		Washer(Bitmap washer, int index)
	{
		super(washer, index);
		dir.x = (float) ((Math.random()*1000)%1000);
		dir.y = (float) ((Math.random()*1000)%1000);
		dir.normalize();
		slow();
		minimalSpeed = staticMinimalSpeedslowness;
	}
	public void setTime(long time)
	{
		minimalSpeed = staticMinimalSpeedslowness * time/10;
	}

	public 		Washer(Bitmap washer, int index, float X, float Y, float height, float width)
	{
		super(washer, index, X, Y, height, width);
		dir.x = (float) ((Math.random()*1000)%1000);
		dir.y = (float) ((Math.random()*1000)%1000);
		dir.normalize();
		slow();
		minimalSpeed = staticMinimalSpeedslowness;
	}
	
	void 		slow()
	{
		dir.multy(slowness);
		float length = dir.getVecLength();
		if(length < minimalSpeed)
		{
			dir.normalize();
			dir.multy(minimalSpeed);
		}
		length = dir.getVecLength();
		if(length > maximalSpeed)
		{
			dir.divide(length);
			dir.multy(maximalSpeed);
		}
	}
	void		addPosition(Vector<DinamicObject> GameObjects)
	{
		pos.add(dir);
		
		boolean isConflict = isConflict(GameObjects);
		
		if (leaveGameZone() || isConflict)
        {
			pos.minus(dir);
            dir.y 	*= -1;
            pos.add(dir);
            
            isConflict = isConflict(GameObjects);            

            if(leaveGameZone() || isConflict)
            {
            	pos.minus(dir);
                dir.multy(-1);

                pos.add(dir);
            }
        }
	}
}
